package core;

public class Match {

	private Team team1;
	private Team team2;
	private int inNbPoints;
	
	public Match(Team t1, Team t2,int nbWinPoint){
		team1=t1;
		team2=t2;
		inNbPoints=nbWinPoint;
	}
	
	public int getTeam1Id(){
		return team1.getId();
	}
	
	public int getTeam2Id(){
		return team2.getId();
	}
	
	public String getTeam1Name(){
		return team1.toString();
	}
	
	public String getTeam2Name(){
		return team2.toString();
	}
	
	public void setScore(int t1,int t2) throws NotEndMatchException{
		if((t1<inNbPoints)&&(t2<inNbPoints))
			throw new NotEndMatchException(inNbPoints);
		int p1=inNbPoints+Math.min(t1,inNbPoints)-Math.min(t2,inNbPoints);
		int p2=inNbPoints+Math.min(t2,inNbPoints)-Math.min(t1,inNbPoints);
		if(t1>t2){
			team1.win(p1,team2.getId());
			team2.loose(p2,team1.getId());
		}
		else{
			if(t1==t2){
				team1.nullMatch(p1,team2.getId());
				team2.nullMatch(p2,team1.getId());
			}
			else{
				team1.loose(p1,team2.getId());
				team2.win(p2,team1.getId());
			}
		}
	}


	
}
